package com.hqx.order.master.controller;


import com.hqx.cloud.output.dto.Order;
import com.hqx.cloud.output.dto.User;
import com.hqx.order.master.feign.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 订单控制器
 * @author: Yz
 * @create: 2020-04-01 15:30
 **/
@RestController
@RefreshScope
public class OrderController {

    @Value("${hqx.name}")
    private String name;

    @Autowired
    private UserFeign userFeign;

    @Value("${server.port}")
    private String port;


    /**
     * 测试feign返回对象
     * @return
     */
    @GetMapping("/getOrder")
    public Order getOrder(){

        User user = userFeign.getUser();
        Order order = new Order();
        if (user != null) {
            order.setUsername(user.getName());
            order.setUserAddr(user.getAddr());
        }
        order.setOrderAddr("order-service:"+port);
        return order;
    }

    /**
     * 测试feign返回字符串
     * @return
     */
    @GetMapping("/getOrderString")
    public String getOrderString(){

        return userFeign.getString();
    }

    /**
     * 测试bus 刷新功能
     * @return
     */
    @GetMapping("/getName")
    public String getName(){

        return name;
    }
}
